
const app = getApp();
let pageNo = 1;
let pageSize = 10;
Page({
  data: {
    listData:[
      {color:"#2F21BC",color2:"#ffffff",title:"专题期刊：XXXXXXX 第一期",title_e:"Special Issue: Issue 1",like:"108",liked: false,nums:"20",dataValues: ['20', '10'],vipStatus:false,},
      {color:"#2F21BC",color2:"#ffffff",title:"塔罗入门：速通版",title_e:"Tarot for Beginners: Quick Pass",like:"177",liked: false,nums:"48",dataValues: ['8', '10'],vipStatus:false,},
      {color:"#2F21BC",color2:"#ffffff",title:"塔罗入门：速通版",title_e:"Tarot for Beginners: Quick Pass",like:"134",liked: false,nums:"38",dataValues: ['20', '40'],vipStatus:true,},
      {color:"#2F21BC",color2:"#ffffff",title:"塔罗入门：速通版",title_e:"Tarot for Beginners: Quick Pass",like:"8",liked: false,nums:"48",dataValues: ['20', '10'],vipStatus:true,},
      {color:"#2F21BC",color2:"#ffffff",title:"塔罗入门：速通版",title_e:"Tarot for Beginners: Quick Pass",like:"68",liked: false,nums:"98",dataValues: ['20', '10'],vipStatus:true,},
    ],
    canvasWidth: 140, // 画布宽度
    progressWidths: [], // 进度条宽度数组
    images: [
        "/resource/images/p_1.png",
        "/resource/images/p_2.png",
        "/resource/images/p_3.png",
        "/resource/images/p_4.png",
      ],
    currentImageIndex: 0,
    page: pageNo, //页数,
    loadmore: 'loadmorenone',//是否显示加载页,
    sessionid:'',
    navTop: app.globalData.navTop+6
  }, 
  attached: function () {
    // 定义导航栏的高度   方便对齐
    this.setData({
      navHeight: app.globalData.navHeight,
      navTop: app.globalData.navTop
    })
  },
  //完结奖励数值
  drawProgress: function() {
    const listData = this.data.listData;
    const canvasWidth = this.data.canvasWidth;
    const progressWidths = listData.map(item => {
      return item.dataValues.map(value => {
        return canvasWidth * value / 100;
      });
    });
    this.setData({
      progressWidths: progressWidths
    });
  },
  //点赞
  liked: function(event) {
    const index = event.currentTarget.dataset.index;
    const newListData = this.data.listData.map((item, idx) => {
        if (idx === index) {
            item.liked = !item.liked; // 切换点赞状态
            if (item.liked) {
                item.like++; // 点赞数加1
            } else {
                item.like--; // 取消点赞，点赞数减1
            }
        }
        return item;
    });
    this.setData({
        listData: newListData
    });
  },
  // 返回上一级
  back: function() {
    wx.navigateBack({
        delta: 1 // 返回上一级页面
    });
  },
  onLoad: function (options) {
   
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.drawProgress(); //完结奖励数值
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow:function(){
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
})